package com.songpeng.provider.demo.service;


import business.service.StorageService;
import com.songpeng.provider.demo.dao.StorageDao;
import com.songpeng.provider.demo.model.Storage;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class StorageServiceImpl implements StorageService {

    @Autowired
    private StorageDao storageDao;

    /**
     * 减库存
     * @param commodityCode
     * @param count
     */
    @Override
    public void deduct(String commodityCode, int count) {
        //synchronized (this) {
            Storage storage = storageDao.getByCommodityCode( commodityCode );
            if (storage != null) {
                storage.setCount( storage.getCount() - count );
            }
            storageDao.updateByPrimaryKeySelective( storage );
        //}
    }
}
